from scrapy.utils.project import get_project_settings

def generate_mongo_conn() -> tuple:
    """
    构造mongodb的连接

    返回：
        url       - mongodb的连接URL
        dbname    - mongodb的数据库名称
        sheetname - mongodb的表名称
    """
    settings = get_project_settings()
    host = settings["MONGODB_HOST"]
    port = settings["MONGODB_PORT"]
    dbname = settings["MONGODB_DBNAME"]
    sheetname = settings["MONGODB_SHEETNAME"]
    user = settings["MONGODB_USER"]
    password = settings["MONGODB_PASS"]
    url = "mongodb://" + user + ":" + password + "@" + host + ":" + str(port)
    return url, dbname, sheetname